using System;
using System.Windows.Input;

namespace Samurai.Client.Commands
{
    public abstract class CommandBase : ICommand
    {
        public Action LongOperationStarted { get; set; }
        public Action LongOperationFinished { get; set; }

        public bool CanExecute(object parameter)
        {
            return InvokeCanExecute(parameter);
        }

        protected virtual bool InvokeCanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            InvokeExecute(parameter);
        }

        protected abstract void InvokeExecute(object parameter);

        protected void InvokeLongOperationStart()
        {
            if (LongOperationStarted != null)
                LongOperationStarted();
        }

        protected void InvokeLongOperationFinish()
        {
            if (LongOperationFinished != null)
                LongOperationFinished();
        }
    }
}